//
//  MPTabBarController.swift
//  Whiteboard
//
//  Created by point on 2018/1/4.
//  Copyright © 2018年 point. All rights reserved.
//

import UIKit

class MPTabBarController: UITabBarController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setupTabBarItem()
    }
    
    fileprivate func setupTabBarItem() {
        
        addChildViewController(HomeViewController(), title: "首页", imageName: kIcon_home,selectedImageName: kIcon_homefill)
        addChildViewController(CircleViewController(), title: "论坛", imageName: kIcon_discover, selectedImageName: kIcon_discoverfill)
        addChildViewController(VenusMyViewController(), title: "我的", imageName: kIcon_my,selectedImageName: kIcon_myfill)
        
    }
    
    
    
    
    
    
}

extension MPTabBarController {
    
    fileprivate func addChildViewController(_ childVC: UIViewController, title : String, imageName : String , selectedImageName: String) {
        childVC.title = title
        childVC.tabBarItem.image = UIImage.icon(from: imageName, color: UIColor.black, imageSize: CGSize(width: 28, height: 28)).withRenderingMode(.alwaysOriginal)
        childVC.tabBarItem.selectedImage = UIImage.icon(from: imageName, color:kColorBtnLigthColor , imageSize: CGSize(width: 28, height: 28)).withRenderingMode(.alwaysOriginal)
        tabBarItem.setTitleTextAttributes([NSAttributedString.Key.font : UIFont.systemFont(ofSize: 18)], for: .normal)
        childVC.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.foregroundColor : kColorBtnLigthColor], for: .highlighted)
        childVC.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.foregroundColor : UIColor.black], for: .normal)
        if UIDevice.isX() {
            childVC.tabBarItem.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: 15);
            childVC.tabBarItem.imageInsets = UIEdgeInsets(top: 10, left: 0, bottom: -10, right: 0);
        }
        
        
        let childNav = MPNavigationController(rootViewController: childVC)
        addChild(childNav)
        
        setCustomtabbar()
    }
    
    fileprivate func setCustomtabbar() {
        //let myTabbar = MPTabBar()
        //self.setValue(myTabbar, forKey: "tabBar")
        //myTabbar.centerBtn .addTarget(self, action: #selector(clickBtn(btn:)), for: .touchUpInside)
        
    }
    
    @objc fileprivate func clickBtn(btn:UIButton) {
        
    }
    
}
